package reflect;

import java.lang.reflect.Constructor;

public class ReflectDemo3 {
    public static void main(String[] args) throws Exception {
        //0.获取Person的Class对象
        Class personClass = Person.class;

        //Constructor<T> getConstructor(类<?>... parameterTypes)
        //传入定义构造器形参的类字节码对象
        System.out.println("-------------传参获取构造器对象-----------------------");
        Constructor constructor = personClass.getConstructor(int.class,String.class,String.class);
        System.out.println(constructor);

        //创建对象  constructor.newInstance();
        System.out.println("-------------利用构造器对象创建person类的实例-----------------------");
        Object person = constructor.newInstance(12,"dokyun","korea");
        System.out.println(person);

        System.out.println("-------------------空参构造器创建person类的实例-------------------");
        Constructor constructor1 = personClass.getConstructor();//获取空构造器对象
        Object person1 = constructor1.newInstance();
        System.out.println(person1);

        System.out.println("-------------利用person类字节码对象创建对象 （方法已弃用）-----------");
        Object o = personClass.newInstance();//Deprecated注解(annotation)已弃用的方法
        System.out.println(o);


    }
}
